package com.his.outpatientvisit.service.impl;

import com.his.finance.dao.FinInvoiceStoreMapper;
import com.his.login.entity.DictEmployee;
import com.his.outpatientvisit.dao.PatiOutVisitInvoiceMapper;
import com.his.outpatientvisit.entity.PatiOutVisitInvoice;
import com.his.outpatientvisit.service.PatiOutVisitInvoiceService;
import com.his.outpatientvisit.vo.PatiOutVisitInvoiceVo;
import com.xiao.common.util.BeanUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class PatiOutVisitInvoiceServiceImpl implements PatiOutVisitInvoiceService {
    @Resource
    private PatiOutVisitInvoiceMapper patiOutVisitInvoiceMapper;

    @Resource
    private FinInvoiceStoreMapper fineInvoiceStoreMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertPatiOutVisitInvoice(DictEmployee employee, PatiOutVisitInvoiceVo patiOutVisitInvoiceVo) throws Exception{
        PatiOutVisitInvoice patiOutVisitInvoice = BeanUtil.copyBean(patiOutVisitInvoiceVo,PatiOutVisitInvoice.class);
        //当前票据号
        String invnow = fineInvoiceStoreMapper.voiceStore_select("060105",employee.getEMPID()).getInvnow();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date today= new Date();
        Date insertdate = simpleDateFormat.parse(simpleDateFormat.format(today));
        Date updatedate = simpleDateFormat.parse(simpleDateFormat.format(today));
        Date invdate = simpleDateFormat.parse(simpleDateFormat.format(today));
        String hospid = employee.getHOSPID();
        String empid = employee.getEMPID();

        patiOutVisitInvoice.setCreatetime(insertdate);
        patiOutVisitInvoice.setUpdatetime(updatedate);
        patiOutVisitInvoice.setInvdate(invdate);
        patiOutVisitInvoice.setHospid(hospid);
        patiOutVisitInvoice.setEmpid(empid);
        patiOutVisitInvoice.setInvoiceid(invnow);

        patiOutVisitInvoiceMapper.out_invoice_add(patiOutVisitInvoice);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void cancPatiOutVisitInvoice(String invoiceId) {
        patiOutVisitInvoiceMapper.out_invoice_canc(invoiceId);
    }


}
